﻿@using Orchard.Utility.Extensions;
@using Orchard.Mvc.Html;
@using Orchard.Mvc.Extensions;
@using System.Linq;
@using RM.Localization.ViewModels;

@{
    // Redesign it as dropdown
    var cultures = Model.Cultures as IEnumerable<CookieCultureItemViewModel> ?? new CookieCultureItemViewModel[0];
}
<select class="dropdown-culture-selector">
    @foreach (var c in cultures) {
        if (!c.Current) {
            <option value="@Url.Action("SetCulture", "CookieCulture", new { Area = "RM.Localization", culture = c.CultureItem.Culture.ToLower(), returnUrl = c.ReturnUrl })">@c.CultureItem.ShortName.ToUpper()</option>
        }
        else
        {
            <option selected value="@Url.Action("SetCulture", "CookieCulture", new { Area = "RM.Localization", culture = c.CultureItem.Culture.ToLower(), returnUrl = c.ReturnUrl })">@c.CultureItem.ShortName.ToUpper()</option>
        }
    }
    <option value="@Url.Action("ResetCulture", "CookieCulture", new { Area = "RM.Localization", returnUrl = Url.Content("~/") })">X</option>
</select>

@using (Script.Foot())
{
<script type="text/javascript">
//<![CDATA[
    (function ($) {
        $(".dropdown-culture-selector").change(function (e) {
            var href = $(".dropdown-culture-selector > option:selected")[0].value;
            window.location = href;
        });
    })(jQuery);
//]]>
</script>
}